package redlib.backend.service.utils;

import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;

import redlib.backend.dto.BillingDetailsDTO;
import redlib.backend.model.BillingDetails;
import redlib.backend.utils.FormatUtils;
import redlib.backend.vo.BillingDetailsVO;

public class BillingDetailsUtils {
    /**
     * 规范并校验departmentDTO
     *
     * @param billingDetailsDTO
     */
    public static void validateBillingDetails(BillingDetailsDTO billingDetailsDTO) {
        FormatUtils.trimFieldToNull(billingDetailsDTO);
        Assert.notNull(billingDetailsDTO, "入数据不能为空");
        Assert.hasText(billingDetailsDTO.getConsumptionName(), "名称不能为空");
    }

    /**
     * 将实体对象转换为VO对象
     *
     * @param billingDetails 实体对象
     * @return VO对象
     */
    public static BillingDetailsVO convertToVO(BillingDetails billingDetails) {
        BillingDetailsVO billingDetailsVO = new BillingDetailsVO();
        BeanUtils.copyProperties(billingDetails, billingDetailsVO);
        billingDetailsVO.setConsumptionTime(FormatUtils.formatFullDate(billingDetails.getConsumptionTime()));
        billingDetailsVO.setModificationTime(FormatUtils.formatFullDate(billingDetails.getModificationTime()));
        return billingDetailsVO;
    }
}
